package xpp.util;
//统一规范json数据的返回值 以便前后端的交互
public class ResultEntity<T> {
    public static final String SUCCESS="SUCCESS";
    public static final String FAILED="FAILED";

    private String result;//用来封装当前请求处理的结果是成功还是失败

    private String message;//请求处理失败返回的错误消息

    private T data;//需要返回的数据
    /*
    * 请求处理成功但是不需要返回数据
    * */
    public static <E> ResultEntity<E> successWithoutData(){
        return new ResultEntity<E>(SUCCESS,null,null);
    }
    /*
     * 请求处理成功但是需要返回数据
     * */
    public static <E> ResultEntity<E> successData(E data){
        return new ResultEntity<E>(SUCCESS,null,data);
    }
    /*
     * 请求处理失败，返回的数据。
     * */
    public static <E> ResultEntity<E> failed(String message){
        return new ResultEntity<E>(FAILED,message,null);
    }
    public ResultEntity() {
    }

    @Override
    public String toString() {
        return "ResultEntity{" +
                "result='" + result + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public ResultEntity(String result, String message, T data) {
        this.result = result;
        this.message = message;
        this.data = data;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}
